package me.zxk.qwert_poetry.dto;

import lombok.Getter;
import lombok.Setter;
import me.zxk.qwert_poetry.dao.Poem;
import me.zxk.qwert_poetry.dao.Tag;

import java.util.List;

@Getter
@Setter
public class PoemDTO {
    private Integer id;
    private String title;
    private String content;
    private Integer authorId;
    private String translation;
    private String annotation;
    private String appreciation;
    private List<Integer> tagIds;


    public static PoemDTO fromEntity(Poem poem) {
        PoemDTO dto = new PoemDTO();
        dto.setId(poem.getId());
        dto.setTitle(poem.getTitle());
        dto.setContent(poem.getContent());
        dto.setAuthorId(poem.getAuthor().getId());
        dto.setTranslation(poem.getTranslation());
        dto.setAnnotation(poem.getAnnotation());
        dto.setAppreciation(poem.getAppreciation());
        dto.setTagIds(poem.getTags().stream().map(Tag::getId).toList());
        return dto;
    }

    public static Poem toEntity(PoemDTO dto) {
        Poem poem = new Poem();
        poem.setId(dto.getId());
        poem.setTitle(dto.getTitle());
        poem.setContent(dto.getContent());
        poem.setTranslation(dto.getTranslation());
        poem.setAnnotation(dto.getAnnotation());
        poem.setAppreciation(dto.getAppreciation());
        return poem;
    }
}
